
package cn.edu.scau.cmi.hombio.service;

import cn.edu.scau.cmi.hombio.domain.Role;
import cn.edu.scau.cmi.hombio.domain.RoleAuthority;
import cn.edu.scau.cmi.hombio.domain.RoleEmployee;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/pigRs-security-context.xml",
		"file:./resources/pigRs-service-context.xml",
		"file:./resources/pigRs-dao-context.xml",
		"file:./resources/pigRs-web-context.xml" })
@Transactional
public class RoleServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected RoleService service;

	/**
	 * Instantiates a new RoleServiceTest.
	 *
	 */
	public RoleServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	* Delete an existing Role entity
	* 
	 */
	@Test
	public void deleteRole() {
		// TODO: JUnit - Populate test inputs for operation: deleteRole 
		Role role = new cn.edu.scau.cmi.hombio.domain.Role();
		service.deleteRole(role);
	}

	/**
	 * Operation Unit Test
	* Return all Role entity
	* 
	 */
	@Test
	public void findAllRoles() {
		// TODO: JUnit - Populate test inputs for operation: findAllRoles 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<Role> response = null;
		response = service.findAllRoles(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllRoles
	}

	/**
	 * Operation Unit Test
	* Return a count of all Role entity
	* 
	 */
	@Test
	public void countRoles() {
		Integer response = null;
		response = service.countRoles();
		// TODO: JUnit - Add assertions to test outputs of operation: countRoles
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findRoleByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findRoleByPrimaryKey 
		Integer id = 0;
		Role response = null;
		response = service.findRoleByPrimaryKey(id);
		// TODO: JUnit - Add assertions to test outputs of operation: findRoleByPrimaryKey
	}

	/**
	 * Operation Unit Test
	* Delete an existing RoleAuthority entity
	* 
	 */
	@Test
	public void deleteRoleRoleAuthorities() {
		// TODO: JUnit - Populate test inputs for operation: deleteRoleRoleAuthorities 
		Integer role_id = 0;
		Integer related_roleauthorities_id = 0;
		Role response = null;
		response = service.deleteRoleRoleAuthorities(role_id, related_roleauthorities_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteRoleRoleAuthorities
	}

	/**
	 * Operation Unit Test
	* Save an existing RoleAuthority entity
	* 
	 */
	@Test
	public void saveRoleRoleAuthorities() {
		// TODO: JUnit - Populate test inputs for operation: saveRoleRoleAuthorities 
		Integer id_1 = 0;
		RoleAuthority related_roleauthorities = new cn.edu.scau.cmi.hombio.domain.RoleAuthority();
		Role response = null;
		response = service.saveRoleRoleAuthorities(id_1, related_roleauthorities);
		// TODO: JUnit - Add assertions to test outputs of operation: saveRoleRoleAuthorities
	}

	/**
	 * Operation Unit Test
	* Delete an existing RoleEmployee entity
	* 
	 */
	@Test
	public void deleteRoleRoleEmployees() {
		// TODO: JUnit - Populate test inputs for operation: deleteRoleRoleEmployees 
		Integer role_id_1 = 0;
		Integer related_roleemployees_id = 0;
		Role response = null;
		response = service.deleteRoleRoleEmployees(role_id_1, related_roleemployees_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteRoleRoleEmployees
	}

	/**
	 * Operation Unit Test
	* Save an existing RoleEmployee entity
	* 
	 */
	@Test
	public void saveRoleRoleEmployees() {
		// TODO: JUnit - Populate test inputs for operation: saveRoleRoleEmployees 
		Integer id_2 = 0;
		RoleEmployee related_roleemployees = new cn.edu.scau.cmi.hombio.domain.RoleEmployee();
		Role response = null;
		response = service.saveRoleRoleEmployees(id_2, related_roleemployees);
		// TODO: JUnit - Add assertions to test outputs of operation: saveRoleRoleEmployees
	}

	/**
	 * Operation Unit Test
	* Load an existing Role entity
	* 
	 */
	@Test
	public void loadRoles() {
		Set<Role> response = null;
		response = service.loadRoles();
		// TODO: JUnit - Add assertions to test outputs of operation: loadRoles
	}

	/**
	 * Operation Unit Test
	* Save an existing Role entity
	* 
	 */
	@Test
	public void saveRole() {
		// TODO: JUnit - Populate test inputs for operation: saveRole 
		Role role_1 = new cn.edu.scau.cmi.hombio.domain.Role();
		service.saveRole(role_1);
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
